package com.example.dao;

import com.example.domain.CommentLike;
import org.apache.ibatis.annotations.*;

public interface CommentLikeMapper {

    // 添加点赞
    @Insert("INSERT INTO comment_like (user_id, comment_id, create_time) VALUES (#{userId}, #{commentId}, #{createTime})")
    void addLike(CommentLike commentLike);

    // 取消点赞
    @Delete("DELETE FROM comment_like WHERE user_id = #{userId} AND comment_id = #{commentId}")
    void removeLike(@Param("userId") Integer userId, @Param("commentId") Integer commentId);

    // 检查用户是否已点赞
    @Select("SELECT COUNT(*) FROM comment_like WHERE user_id = #{userId} AND comment_id = #{commentId}")
    int isLiked(@Param("userId") Integer userId, @Param("commentId") Integer commentId);

    // 获取评论点赞数
    @Select("SELECT COUNT(*) FROM comment_like WHERE comment_id = #{commentId}")
    int getLikeCount(@Param("commentId") Integer commentId);

    // 获取用户点赞的评论列表
    @Select("SELECT comment_id FROM comment_like WHERE user_id = #{userId}")
    java.util.List<Integer> getUserLikedComments(@Param("userId") Integer userId);
}
